package org.example.BIO_02;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 多发 多收
 * S端一直阻塞等待C端发送消息，等待阻塞,端对端
 *
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        System.out.println("服务端启动，端口：9999");
        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        // 转为缓冲字符流
        BufferedReader bf = new BufferedReader(new InputStreamReader(is));
        // 阻塞等待消息并接收
        String msg;
        while((msg = bf.readLine()) != null) {
            System.out.println("服务端接收到消息："+ msg);
        }
    }
}
